<template>
	<div>
		<el-select v-model="SelSysCompanyId" placeholder="请选择企业" filterable @click="getSysCompanyData" :style="selectStyle">
		  <el-option v-for="i in sysCompanyOptions" :key="i.sysCompanyId" :label="i.companyName" :value="i.sysCompanyId"></el-option>
		</el-select>
	</div>
	<div v-show="hasSelSysBranchOffice">
		<el-select v-model="SelSysBranchOfficeId" placeholder="请选择分公司" filterable :style="selectStyle"><!-- :style="{'width':selectWidth}"> -->
		  <el-option v-for="m in sysBranchOfficeOptions" :key="m.sysBranchOfficeId" :label="m.officeName" :value="m.sysBranchOfficeId"></el-option>
		</el-select>
	</div>
	<div v-show="SystemLevelShow">
		<el-select v-model="SystemLevelId"  placeholder="请选择系统" filterable :style="selectStyle">
		  <el-option v-for="i in systemLevelOptions" :key="i.systemLevelTypeId" :label="i.typeName" :value="i.systemLevelTypeId"></el-option>
		</el-select>
	</div>
</template>
<script>
/** 企业 --》 分公司---》系统  **/
	import sysCompanyAPI from '@/api/system/sysCompany';
	import sysBranchOfficeAPI from '@/api/system/sysBranchOffice';
	import systemLevelBranchAPI from '@/api/system/systemLevelBranch';
	export default {
		name: "selectBranchSystemCO",
		props: ["parentLoadingFunction",//等待显示回调函数
				"parentGetData",//加载数据回调函数
				"selectStyle",//宽度
			],
		data() {
			return {
				SelSysCompanyId: null,
				SelSysBranchOfficeId: null,
				sysCompanyOptions: [],
				sysBranchOfficeOptions: [],
				hasSelSysBranchOffice: false,
				SystemLevelShow: false,
				SystemLevelId: null,
				systemLevelOptions: [],
			}
		},
		watch: {
			SelSysCompanyId(val){//选中企业值触发
				if(val){
					this.getSysBranchOfficeData();
				}
			},
			SelSysBranchOfficeId(val){//选中分公司值触发
				if(val){
					this.getSystemLevelData();//回调加载数据
				}
			},
			SystemLevelId(val){//选中系统
				if(val){
					this.parentGetData(this.SelSysBranchOfficeId,val);//回调加载数据
				}
			},
		},
		computed: {
		},
		mounted(){
		},
		methods: {
			async getSysCompanyData(){//加载企业数据
				if(this.sysCompanyOptions.length < 1){
					this.parentLoadingFunction(true);
					let reqData = {"current": 1,"size": 1000};
					var res = await sysCompanyAPI.sysCompany.init.get(reqData);
					this.parentLoadingFunction(false);
					if(res.code === 2000){
						this.sysCompanyOptions=res.data.records;
					}else{
						this.$message.warning(res.message);
					}
				}
			},
			async getSysBranchOfficeData(){/** 加载分公司数据 **/
				this.sysBranchOfficeOptions=[];this.hasSelSysBranchOffice = true; this.SelSysBranchOfficeId = null;
				this.systemLevelOptions=[];this.SystemLevelShow = false; this.SystemLevelId = null;
				this.parentLoadingFunction(true);
				let reqData = {"current": 1,"size": 100,"sysCompanyId": this.SelSysCompanyId};
				var res = await sysBranchOfficeAPI.sysBranchOffice.list.get(reqData);
				this.parentLoadingFunction(false);
				if(res.code === 2000 && res.data.records){
					this.sysBranchOfficeOptions=res.data.records;
					if(this.sysBranchOfficeOptions.length==1){/** 没有分公司 **/
						this.SelSysBranchOfficeId = this.sysBranchOfficeOptions[0].sysBranchOfficeId;
						this.hasSelSysBranchOffice = false;
					}
				}else{
					this.$message.warning(res.message);
				}
			},
			async getSystemLevelData(){
				this.systemLevelOptions=[];this.SystemLevelShow = true; this.SystemLevelId = null;
				let reqData = {"current": 1,"size": 100,"sysBranchOfficeId" : this.SelSysBranchOfficeId};
				var res = await systemLevelBranchAPI.systemLevelBranch.list.get(reqData);
				this.parentLoadingFunction(false);
				if(res.code === 2000){
					this.systemLevelOptions=res.data.records;
				}else{
					this.$alert(res.message, "提示", {type: 'error'});
				}
			},
		}
	}
</script>
